/**
 * Created with IntelliJ IDEA.
 * Description
 * User: cjc
 * Date: 2025-03-01
 * Time: 10:34
 */
public class Test {
    //汉诺塔
    public static void move(char pos1,char pos2) {
        System.out.print(pos1+ "->"+pos2+" ");
    }
    public static void hanoi(int n,char pos1,char pos2,char pos3) {
        if(n == 1) {
            move(pos1,pos3);
            return;
        }
        hanoi(n-1,pos1,pos3,pos2);
        move(pos1,pos3);
        hanoi(n-1,pos2,pos1,pos3);
    }

    //n的阶乘
    public static int n(int n) {
        if(n == 1) {
            return 1;
        }
        return n*n(n-1);
    }

    //返回组成它的数字之和
    public static int SumNum(int num) {
        if (num < 10) {
            return num;
        }
        return num % 10 + SumNum(num / 10);
    }

    // 递归求 1 + 2 + 3 + ... + 10
    public static int Sum(int n) {
        if(n==1) {
            return 1;
        }
        return n + Sum(n-1);
    }

    //斐波那契数列
    public static  int fib(int n) {
        if(n == 1 || n == 2) {
            return 1;
        }
        return fib(n-1) + fib(n- 2);
    }

    //正序输出数字
    public static void print(int n) {
        if(n>9) {
            print(n / 10);
        }
            System.out.print(n % 10+" ");
    }
    public static void main(String[] args) {
        print(123);
        System.out.println("");
        System.out.println(fib(4));
        System.out.println(Sum(10));
        System.out.println(SumNum(123));
        System.out.println(n(4));
        hanoi(3,'A','B','C');
    }
}
